package com.lagou.mr.sorttest;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class SortDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(SortDriver.class);//程序执行入口
        job.setMapperClass(SortMapper.class);//mapper
        job.setReducerClass(SortReduce.class);//reduce

        job.setMapOutputKeyClass(SortBean.class);//map输出数据类型 key
        job.setMapOutputValueClass(NullWritable.class);//map输出数据类型 value

        job.setOutputKeyClass(SortBean.class);
        job.setOutputValueClass(NullWritable.class);

        //指定文件读取路径
        FileInputFormat.setInputPaths(job,new Path("D:\\Program Files\\JetBrains\\hadoopWorkspace\\wordcount\\src\\main\\resources\\test"));
        //指定文件生成路径
        FileOutputFormat.setOutputPath(job,new Path("D:\\Program Files\\JetBrains\\hadoopWorkspace\\wordcount\\src\\main\\resources\\output"));
        boolean flag = job.waitForCompletion(true);
        System.exit(flag? 0:1);

    }
}
